<?php

namespace loggedin\controller;

require_once("/loggedin/model/GetQuestions.php");
require_once("/login/view/Userinfo.php");
require_once("/loggedin/view/QuestionView.php");

class QuestionController {
	/**
	 * @var \loggedin\model\GetQuestions
	 */
	private $getQuestionsModel;
	/**
	 * @var \login\view\UserInfo
	 */
	private $userInfo;
	/**
	 * @var \loggedin\view\QuestionView
	 */
	private $questionView;


	function __construct(\loggedin\model\GetQuestions $getQuestionsModel,
						 \login\view\UserInfo $userInfo, 
						 \loggedin\view\QuestionView $questionView) {
		$this->getQuestionsModel = $getQuestionsModel;
		$this->userInfo = $userInfo;
		$this->questionView = $questionView;
	}

	/**
	 * @return HTML string
	 */
	public function getLoggedinUsersQuestions() {
		$mysqli = new \mysqli("mysql08.citynetwork.se", "119958-mg18906",
							  "quizzer50", "119958-quizzer");
		$loggedinUserName = $this->userInfo->getUserLoggedinInfo();
		$questions = $this->getQuestionsModel->getAllQuestions($mysqli, $loggedinUserName);
		$mysqli->close();
		$htmlQuestions = $this->questionView->getQuestionsToHTML($questions);
		return $htmlQuestions;
	}
}